package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.PayDivideVO;
import com.jishuo.nontax.bfc.service.DivideService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @auther dinggaofei
 * @Date 2023/3/14 9:25
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/divide", name = "划解分成单据")
@UserAuthority(menu = {"bill/divide/divide", "sys/basedata/basedata"})
public class divideController {

    @Resource
    private DivideService divideService;
    @Resource
    private UserService userService;

    // 页面文件位置
    private String prefix = "bill/";

    @RequestMapping(value = {"divide"}, name = "化解分成首页")
    public String index() {
        return prefix + "divide";
    }


    @ResponseBody
    @RequestMapping(value = "findDividePage", name = "化解分成列表")
    public GridResult<PayDivideVO> findDividePage(PayDivideVO payDivideVO, Pagination pagination) {
        List<PayDivideVO> dividePage = divideService.findDividePage(payDivideVO, pagination);
        return  new GridResult<>(dividePage);

    }

    @ResponseBody
    @RequestMapping(value = "sendDivide",name = "发送分成单据")
    public BaseResult sendDivide(String billids , String userpwd, String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  divideService.sendDivide(billids);
    }

    @ResponseBody
    @RequestMapping(value = "cleanDivide",name = "冲销专户单据")
    public BaseResult cleanDivide(String billids , String userpwd, String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  divideService.cleanDivide(billids, usercode);
    }

    @ResponseBody
    @RequestMapping(value = "divideExport",name = "专户导出")
    public void divideExport(long bankid, String paybankdt, HttpServletResponse response){
          divideService.divideExport(bankid, paybankdt, response);
    }
}
